/*
 * Loggerable.h
 *
 *  Created on: 2009/01/31
 *      Author: Yongshik Cho
 */

#ifndef LOGGERABLE_H_
#define LOGGERABLE_H_

#include "../core/Prerequisites.h"
#include "../core/ISmartPtr.h"
#include <fstream>

//#include "sqplus/sqplus.h"
//using namespace SqPlus;


class Loggerable: public ISmartPtr<Loggerable>
{
public:
	static const String _DEFAULT_TIME_STAMP_FORMAT;
	static const String _DEFAULT_FILENAME;
	static const String _EXT_LOG;

public:
	Loggerable(String path = _T(""), String formatTimeStamp = _DEFAULT_TIME_STAMP_FORMAT);
	virtual ~Loggerable();

public:
	inline const String& getPath() const { return mPath; }
#if UNICODE
	inline wofstream& getStream() { return mStream; }
#else
	inline ofstream& getStream() { return mStream; }
#endif

	/** Function for writing to a stream.
	*/
#if UNICODE
	template<typename T>
	wofstream& operator << (const T&  value)
#else
	template<typename T>
	ofstream& operator << (const T&  value)
#endif
	{
		mStream << value;
		return mStream;
	}

	virtual void printTimeStamp();

private:
#if UNICODE
	wofstream	mStream;
#else
	ofstream	mStream;
#endif
	String		mPath;
	String		mTimeStampFormat;
	bool		mLineStart;
};

//must be declared here
//DECLARE_INSTANCE_TYPE(Loggerable)

#endif /* LOGGERABLE_H_ */
